/*
 * @Author: Scrooge yu844856744@qq.com
 * @Date: 2023-05-31 10:27:45
 * @LastEditors: Scrooge yu844856744@qq.com
 * @LastEditTime: 2023-06-09 11:46:11
 * @FilePath: /seehoo-design-plus/src/components/sh-search/utils/useExpand.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { ref, unref } from 'vue';
import { useLayout } from './useLayout';

/**
 * @description: search 展开收起功能
 */
export const useExpand = props => {
  const isExpand = ref(false);
  let { searchConfigs } = useLayout(props);
  /**
   * @description: 控制展开收起
   * @param: searchConfigs<Array> 所有数据的总和
   * @returns: 修改 isExpand 的状态，并且修改数据的hidden达到隐藏的效果
   */
  const onExpand = () => {
    searchConfigs.value[0].list = searchConfigs.value[0].list.map(item => {
      if ('hidden' in item) {
        item.hidden = isExpand.value;
      }
      return item;
    });
    isExpand.value = !isExpand.value;
  };

  return {
    isExpand,
    onExpand,
  };
};
